package com.example.mobile2021606134chhnewdemo.WeatherModule;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mobile2021606134chhnewdemo.R;

import java.util.ArrayList;
import java.util.List;

public class WeatherAdapter extends RecyclerView.Adapter<WeatherAdapter.ViewHoder> {
    List<Weather> list = new ArrayList<>( );




    public WeatherAdapter(List<Weather> list) {
        this.list = list;

    }

    @NonNull
    @Override
    public ViewHoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext( )).inflate(R.layout.item_rv_weather, parent, false);
        return new ViewHoder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHoder holder, int position) {

        Weather weather = list.get(position);
        holder.tvDate.setText(weather.getDate());
        holder.tvweather.setText(weather.getWeather());
        holder.tvMix.setText("最高气温"+weather.getMixtemp()+"℃");
        holder.tvless.setText("最高气温"+weather.getLesstemp()+"℃");
       holder.ivWeather.setImageResource(weather.getpicture());

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHoder extends RecyclerView.ViewHolder {
        TextView tvDate,tvless,tvMix,tvweather;
        ImageView ivWeather;
        public ViewHoder(@NonNull View itemView) {
            super(itemView);
            tvDate = itemView.findViewById(R.id.tvItemDate);
            tvless = itemView.findViewById(R.id.tvItemLess);
            tvMix = itemView.findViewById(R.id.tvItemMax);
            tvweather = itemView.findViewById(R.id.tvItemWeather);
            ivWeather = itemView.findViewById(R.id.ivItemWeather);
        }
    }
}
